package com.haofengsoft.scce.db.biz;

import java.util.List;

import android.content.Context;

import com.haofengsoft.scce.ManageApplication;
import com.haofengsoft.scce.db.DaoSession;
import com.haofengsoft.scce.db.bean.AdvertInfo;
import com.haofengsoft.scce.db.dao.AdvertInfoDao;

import de.greenrobot.dao.query.QueryBuilder;

/**
 * Created by weiwei on 15/6/15.
 */
public class AdvertInfoBiz {
	private static AdvertInfoBiz instance;
	private static Context appContext;
	private AdvertInfoDao dao;

	private AdvertInfoBiz() {
	}

	public static AdvertInfoBiz getInstance(Context context) {
		if (instance == null) {
			instance = new AdvertInfoBiz();
			if (appContext == null) {
				appContext = context.getApplicationContext();
			}
			DaoSession daoSession = ManageApplication.getDaoSession(context);
			instance.dao = daoSession.getAdvertInfoDao();
		}
		return instance;
	}

	public void insertAddressInfoList(final List<AdvertInfo> infoList) {
		dao.insertOrReplaceInTx(infoList);
	}

	public List<AdvertInfo> gainAdvertList() {
		QueryBuilder qb = dao.queryBuilder();
		qb.where(AdvertInfoDao.Properties.Status.notEq(0));
		return qb.list();
	}
}
